import Vue from 'vue'
import App from './App.vue'
import config from './common/config.js';
Vue.prototype.$config = config;
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);
import router from './router'


import core_enums from './common/core_enums.js';
Vue.use({
  install(Vue) {
    Vue.prototype.$core_enums = function (name) {
      if (typeof (core_enums[name]) == 'undefined') {
        return [];
      }
      var d = [];
      for (var i in core_enums[name]) {
        d.push({
          key: String(i),
          value: core_enums[name][i]
        });
      }
      return d;
    };
  }
});

import Cookies from 'js-cookie';
import axios from 'axios';

import encryption from './common/encryption.js';
Vue.prototype.$encryption = encryption;

axios.defaults.baseURL = config.axios_baseURL;
axios.interceptors.request.use(function (config) {
  // 在发送请求之前做些什么
  config.headers['Authorization'] = JSON.stringify({
    auth: Cookies.get('auth'),
    userid: Cookies.get('userid'),
    username: Cookies.get('username'),
    groupid: Cookies.get('groupid'),
    rsa_token: encryption(),
  });
  return config;
}, function (error) {
  // 对请求错误做些什么
  return Promise.reject(error);
});
axios.interceptors.response.use(function (response) {
  // 对响应数据做点什么
  return response.data;
}, function (error) {
  // 对响应错误做点什么
  if (error.response.status == 401) {
    router.replace({
      path: '/msg',
      query: { code: 401 },
    });
    return error.response;
  }
  if (error.response.status == 403) {
    router.replace({
      path: '/msg',
      query: { code: 403 },
    });
    return error.response;
  }
  return error;
});

Vue.prototype.$axios = axios;


import Aside from './components/Aside.vue';
import Header from './components/Header.vue';
import Footer from './components/Footer.vue';
import CategoryAdd from './components/Category-add.vue';
import CategoryMod from './components/Category-mod.vue';
import CategoryLst from './components/Category-lst.vue';

Vue.component('Aside', Aside);
Vue.component('Header', Header);
Vue.component('Footer', Footer);
Vue.component('CategoryAdd', CategoryAdd);
Vue.component('CategoryMod', CategoryMod);
Vue.component('CategoryLst', CategoryLst);

import tinymce from './common/tinymce.js';
Vue.prototype.$tinymce = tinymce;

import Editor from "@tinymce/tinymce-vue";
import store from './store'
Vue.component('TinymceEditor', Editor);

Vue.config.productionTip = false


new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
